package com.example.demo.strategy;

import com.example.demo.enums.CalculationEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Component
public class StrategySetFactory {
    private Map<CalculationEnum,CalculationMethodStrategy> strategyMap;

    @Autowired
    public StrategySetFactory(Set<CalculationMethodStrategy> strategySet) {
        createStrategy(strategySet);
    }

    private void createStrategy(Set<CalculationMethodStrategy> strategySet) {
        strategyMap = new HashMap<CalculationEnum,CalculationMethodStrategy>();
        strategySet.forEach(strategy -> {
            strategyMap.put(strategy.getCalculationEnum(), strategy);
        });
    }

    public CalculationMethodStrategy getStrategy(CalculationEnum calculationEnum) {
        return strategyMap.get(calculationEnum);
    }
}
